#ifndef HAL_CANFD_H_
#define HAL_CANFD_H_
/*===========================================================================*/
/**
 * @file hal_canfd.h
 *
 * @brief Hardware Abstraction Layer for CAN FD (MCAN) peripheral.
 *
 *------------------------------------------------------------------------------
 *
 * Copyright (C) 2025 . All rights reserved.
 *
 *------------------------------------------------------------------------------
 *
 * @section DESC DESCRIPTION:
 *   - Hardware abstraction and configuration interface for CAN FD peripherals.
 *   - Encapsulates initialization, bit-timing configuration, TX/RX, and error handling.
 *
 * @section ABBR ABBREVIATIONS:
 *   - MCAN: Modular Controller Area Network (CAN FD)
 *   - FD: Flexible Data-rate
 *
 * @section TRACE TRACEABILITY INFO:
 *   - Design Document(s):
 *     - CAN FD HAL Design Spec v1.0
 *   - Requirements Document(s):
 *     - See System Integration Spec Section 3.4
 *   - Applicable Standards:
 *     - ESGW_4-2_PE-SWx_00-01-A02_EN - C Coding Standards [20120506]
 *
 * @section DFS DEVIATIONS FROM STANDARDS:
 *   - None.
 *
 * @defgroup hal_canfd CAN FD HAL API
 * @{
 */
/*==========================================================================*/

/*===========================================================================*
 * Standard Header Files
 *===========================================================================*/
#include <stdint.h>
#include <stdbool.h>
#include <driverlib.h>

/*===========================================================================*
 * Exported Type Declarations
 *===========================================================================*/


// MCAN(CAN FD) 时钟分频
typedef enum Hal_Canfd_Clk_Div_Tag{
    HAL_CANFD_CLK_DIV_1 = 0,
    HAL_CANFD_CLK_DIV_2,
    HAL_CANFD_CLK_DIV_3,
    HAL_CANFD_CLK_DIV_4,
    // ...如有更多分频选项可扩展
} Hal_Canfd_Clk_Div_T;

// BIT timing结构体（可根据需要再扩展）
typedef struct Hal_Canfd_BitTiming_Tag
{
    uint32_t prescaler;
    uint32_t tseg1;
    uint32_t tseg2;
    uint32_t sjw;
} Hal_Canfd_BitTiming_T;

// MCAN配置结构体
typedef struct Hal_Canfd_Config_Tag
{
    uint32_t base_addr;
    bool     fd_enable;
    bool     brs_enable;
    Hal_Canfd_BitTiming_T nominal;
    // ...更多可选项如ram地址、buffer数量等
    uint32_t rx_id;      // <== UDS物理寻址ID，务必加上
        // ... 其它参数
} Hal_Canfd_Config_T;

/*===========================================================================*
 * Exported Function Prototypes
 *===========================================================================*/

/**
 * @brief 配置MCAN(CAN FD)的外设时钟分频
 * @param div 分频系数
 */
extern void hal_canfd_set_clk_div(Hal_Canfd_Clk_Div_T div);

extern void hal_canfd_gpio_init(void);

/**
 * @brief 初始化CAN FD（MCAN）模块
 */
extern bool hal_canfd_init(const Hal_Canfd_Config_T* cfg);

/**
 * @brief 发送一个CAN FD帧
 */
extern bool hal_canfd_transmit(uint32_t id, const uint8_t *data, uint8_t len, bool ext_id);


// 接收API声明
bool hal_canfd_receive(uint32_t *id, uint8_t *data, uint8_t *len, bool *ext_id);

/**
 * @brief 定义其它操作如接收、RAM配置等（可扩展）
 */


// 其它CAN FD相关初始化/收发API都可以补充进来

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* HAL_CANFD_H_ */
/*============================================================================*\
 * AUTHOR(S) IDENTITY (AID)
 *-----------------------------------------------------------------------------
 *  XG   Xianzhi Gong   njp4bz
\*============================================================================*/

/*============================================================================*\
 * FILE REVISION HISTORY
 *-----------------------------------------------------------------------------
 *  DATE        REVISION   AID   SUMMARY OF CHANGES
 *  ---------------------------------------------------------------------------
 *  2025-05-28  1.00       XG    Initial version
 *  ---------------------------------------------------------------------------
\*============================================================================*/
/* END OF FILE -------------------------------------------------------------- */
